<?php
	class SqlHelper{
		
		private $conn;
		private $server="localhost";
		private $user="root";
		private $password="123456";
		private $db_name="smartytest";
		//寰楀埌涓�釜閾炬帴
		public function getConn(){	
			$this->conn=mysql_connect($this->server,$this->user,$this->password) or die (mysql_error());
			mysql_select_db($this->db_name,$this->conn) or die (mysql_error());
			mysql_query('set names utf-8',$this->conn);
			return $this->conn;
		}
		//鍏抽棴閾炬帴
		public function closeCon(&$conn){
			mysql_close($conn) or die(mysql_error());
		}
		
		//鎻愪緵涓�釜鏌ヨ鐨勭粺涓�嚱鏁�
		public function execute_sql($sql){
			$this->getConn();
			$result=mysql_query($sql) or die(mysql_error());
			
			$arr=array();
			while($row=mysql_fetch_assoc($result)){
				$arr[]=$row;
			}
			mysql_free_result($result);
			return $arr;
		}
		//鎻愪緵涓�釜鎵цdml(delete,update,insert)鍑芥暟
		public function execute_dml($sql){
			$this->getConn();
			mysql_query($sql) or die(mysql_error());
		}
	}
?>